class LogsController < ApplicationController
  before_filter :check_authorization
  layout "project"
  # GET /logs
  # GET /logs.xml
  def index
    @page_title = @project.name + " > " + "Overview".t
    @logs = Log.find(:all,:conditions=>["project_id = ?",params[:project_id]],:order=>'id desc',:limit=>'0,20')
    if @project.milestones.size > 0
      @data = gantt_data(@project)[:data]
      @height = gantt_data(@project)[:height]
    end
    respond_to do |format|
      format.html # index.rhtml
      format.xml  { render :xml => @logs.to_xml }
    end
  end

  # GET /logs/1
  # GET /logs/1.xml
  def show
    @log = Log.find(params[:id])

    respond_to do |format|
      format.html # show.rhtml
      format.xml  { render :xml => @log.to_xml }
    end
  end

  # GET /logs/new
  def new
    @log = Log.new
  end

  # GET /logs/1;edit
  def edit
    @log = Log.find(params[:id])
  end

  # POST /logs
  # POST /logs.xml
  def create
    @log = Log.new(params[:log])
    @log.project_id = params[:project_id]

    respond_to do |format|
      if @log.save
        flash[:notice] = 'Log was successfully created.'
        format.html { redirect_to log_url(@log) }
        format.xml  { head :created, :location => log_url(@log) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @log.errors.to_xml }
      end
    end
  end

  # PUT /logs/1
  # PUT /logs/1.xml
  def update
    @log = Log.find(params[:id])

    respond_to do |format|
      if @log.update_attributes(params[:log])
        flash[:notice] = 'Log was successfully updated.'
        format.html { redirect_to log_url(@log) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @log.errors.to_xml }
      end
    end
  end

  # DELETE /logs/1
  # DELETE /logs/1.xml
  def destroy
    @log = Log.find(params[:id])
    @log.destroy

    respond_to do |format|
      format.html { redirect_to logs_url }
      format.xml  { head :ok }
    end
  end
end
